Skip to content

fix(discovery-index): bound TtlCache by a max-entry cap enforced on set - #10145

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10029
Jul 31, 2026
Merged

fix(discovery-index): bound TtlCache by a max-entry cap enforced on set#10145
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10029

Conversation

@bitfathers94

Copy link
Copy Markdown
Contributor

fix(discovery-index): bound TtlCache by a max-entry cap enforced on set

Closes #10029

@bitfathers94
bitfathers94 requested a review from JSONbored as a code owner July 31, 2026 09:07
@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-31 09:26:22 UTC

3 files · 1 AI reviewer · no blockers · readiness 93/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This adds a max-entry cap to TtlCache, enforced only on the first insert of a new key: it drops already-expired entries, then evicts oldest-inserted entries until back under the cap, and threads a shared DEFAULT_CACHE_MAX_ENTRIES (5000) through all three server.ts cache construction sites. The logic is correct, including the edge case of a cap of 0 (evictForCapacity clears down to 0 before the new entry is inserted, so size settles at 1) and the overwrite-never-evicts case for existing keys. Test coverage is thorough, covering cap enforcement, expiry-first eviction, overwrite behavior, the default fallback, a 0-cap edge case, and a source-text-based check that server.ts wires the default into all three constructors — directly closing the referenced issue #10029 about unbounded cache growth.

Nits — 4 non-blocking
  • nit: evictForCapacity's expiry sweep is O(n) over the whole map on every capacity-triggered set once the cache is full, so under sustained new-key churn at the cap this runs a full scan per insert — cache.ts:44-49 — worth a comment noting this is an accepted tradeoff given the cache's stated small/cheap-to-recompute entries, or consider capping the sweep.
  • nit: the server.ts wiring test (cache.test.ts:139-150) asserts via regex/string-matching against source text rather than actual TS type-checking, so it can't catch a construction site that's syntactically well-formed but semantically wrong (e.g. passing the cap as the wrong constructor argument) — acceptable given server.ts's stated untestable-entrypoint status, but worth noting as a weaker guarantee than a real import-based test.
  • Consider documenting the O(n) sweep tradeoff in evictForCapacity directly (cache.ts:44) since it's the one place performance could matter if entry volume grows well past 5,000.
  • The three server.ts call sites (server.ts:29-32) could default to DEFAULT_CACHE_MAX_ENTRIES implicitly instead of being passed explicitly, but explicit is arguably clearer here and matches the PR's intent to make the cap visible at each site — no change needed.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #10029
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ⚠️ 20/25 Preflight is ready, but the PR body does not name the validation run.
Contributor workload ✅ 10/10 Author activity: 119 registered-repo PR(s), 82 merged, 3 issue(s).
Contributor context ✅ Confirmed Gittensor contributor bitfathers94; Gittensor profile; 119 PR(s), 3 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
TtlCache now takes a maxEntries cap with an exported DEFAULT_CACHE_MAX_ENTRIES default, enforces it in set() by first dropping expired entries then evicting oldest-inserted via Map insertion order (no timers), and server.ts passes the cap explicitly at all three construction sites without changing SoftClaimStore's signature or TTL values.

Review context
  • Author: bitfathers94
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: TypeScript
  • Official Gittensor activity: 119 PR(s), 3 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Add validation command/output.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.96%. Comparing base (07df5ca) to head (1b238ea).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10145   +/-   ##
=======================================
  Coverage   79.95%   79.96%           
=======================================
  Files         282      283    +1     
  Lines       58728    58757   +29     
  Branches     6930     6939    +9     
=======================================
+ Hits        46958    46987   +29     
  Misses      11480    11480           
  Partials      290      290           
Flag Coverage Δ
backend 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/discovery-index/src/cache.ts 100.00% <100.00%> (ø)

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 1807ff4 into JSONbored:main Jul 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

discovery-index(cache): bound TtlCache so a never-re-read key is actually freed instead of living for the process lifetime

1 participant